--[[
    玩家游戏实体
]]--

local blaze = require "blaze"
local game = require "club.threecard.bjracing"
local gamelib = require "club.threecard.gamelib"

local GameObject = require "entities.interfaces.GameObject"
local Client = require "entities.interfaces.Client"
local Player = require "entities.interfaces.Player"

local M = game.kbe.entity("GDPPlayer", GameObject, Client, Player)

function M:__init__()
    GameObject.__init__(self)
    Client.__init__(self)
    Player.__init__(self)
end

--[[ =============================
             服务端接口
================================== ]]--

function M:bet(amount)
    self.log.debug("bet:"..amount);
    self:cellCall("bet", amount)
end

function M:exchange(card_uids)
    self.log.debug("exchange:"..#card_uids);
    self:cellCall("exchange", card_uids)
end

function M:see(flags)
    self.log.debug("see:"..flags);
    self:cellCall("see", flags)
end

--[[ =============================
             属性变更回调
================================== ]]--

function M:set_can_bet(old)
    local args = 
    {
        can_bet = game.kbe.player().can_bet;
        can_see = game.kbe.player().can_see;
        can_exchange = game.kbe.player().can_exchange;
    }
    game.store.ingame.on_ope_status(args);
end

function M:set_can_see(old)
    local args = 
    {
        can_bet = game.kbe.player().can_bet;
        can_see = game.kbe.player().can_see;
        can_exchange = game.kbe.player().can_exchange;
    }
    game.store.ingame.on_ope_status(args);
end

function M:set_can_exchange(old)
    local args = 
    {
        can_bet = game.kbe.player().can_bet;
        can_see = game.kbe.player().can_see;
        can_exchange = game.kbe.player().can_exchange;
    }
    game.store.ingame.on_ope_status(args);
end

function M:set_chip(old)
    game.store.ingame.on_change_chip({old = old});
end

function M:set_bet_amount(old)
    local args = 
    {
        bet_amount = game.kbe.player().bet_amount;
        old = old;
    }
    game.store.ingame.on_change_bet_amount(args);
end

function M:set_hand_card_uids(old)
    self.log.debug("set_hand_card_uids");
end

--[[ =============================
             服务端回调
================================== ]]--

function M:onEnterWorld()
    --Entity.onEnterWorld(self)
    Client.on_enter_world(self)
end

function M:onLeaveWorld()
    --Entity.onLeaveWorld(self)
    Client.on_leave_world(self)
end

function M:on_deal(card_uids)
    game.store.ingame.on_deal({card_uids = card_uids});
end

function M:on_see(card_uids)
    game.store.ingame.on_see({card_uids = card_uids});
end

function M:on_exchange(card_uids)
    game.store.ingame.on_exchange({card_uids = card_uids});
end

function M:on_settlement(game_settlement)
    game.store.ingame.on_settlement({info = game_settlement});
end

function M:on_game_init(game_init_info)
    self.log.debug("game_init");
    self.log.debug(blaze.dump(game_init_info));
end

return M